<template>
  <div class="scriptWriting">
    <el-form
      :inline="true"
      :model="formInline"
      class="demo-form-inline"
      size="small"
    >
      <el-form-item label="作品名称">
        <el-input
          v-model="formInline.title"
          placeholder="作品名称"
          clearable
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" border style="width: 100%" height="620px" :fit="true">
      <el-table-column prop="title" label="作品名称" width="200"/>
      <el-table-column prop="publisher" label="作者" width="80"/>
      <el-table-column prop="creationTypeName" label="创作类型" width="80"/>
      <el-table-column prop="scanType" label="观看类型" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row.scanType == 0 ? '授权' : '免费' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="price" label="价格" width="80"/>
      <el-table-column prop="workState" label="状态" width="80">
        <template slot-scope="scope">
          <span v-if="scope.row.workState == 1">草稿</span>
          <span v-if="scope.row.workState == 2">待审核</span>
          <span v-if="scope.row.workState == 3">已审核</span>
          <span v-if="scope.row.workState == 4">驳回</span>
          <span v-if="scope.row.workState == 5">已上架</span>
          <!--          <span>{{ status(scope.row.workState) }}</span>-->
          <!--          <span v-if="scope.row.workState==4&&scope.row.overRule">({{ scope.row.overRule }})</span>-->
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间"/>
      <el-table-column label="操作" width="150">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.workState != 2"
            type="primary"
            size="mini"
            @click="review(scope.row)"
          >查看
          </el-button>
          <el-button
            v-if="scope.row.workState == 2"
            type="warning"
            size="mini"
            @click="review(scope.row)"
          >审 核
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block pageCont">
      <el-pagination
        :current-page="currentPage"
        :page-size="pageSizes"
        layout="total, prev, pager, next, jumper"
        :total="total"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>
<script>
  import { ScriptWritingList } from '@/api/ScriptWriting'
  import _ from 'lodash'

  export default {
    data() {
      return {
        tableData: [],
        formInline: {},
        currentPage: 1,
        total: 0,
        pageSizes: 20,
        workStateList: [
          { label: '草稿', id: 1 },
          { label: '待审核', id: 2 },
          { label: '审核通过', id: 3 },
          { label: '驳回', id: 4 }
        ]
      }
    },
    created() {
      this.getList()
    },
    methods: {
      review(row) {
        this.$router.push({ name: 'scriptWritingReview', query: { id: row.id } })
      },

      // status(d) {
      //   return _.filter(this.workStateList, (v) => v.id == d)[0].label
      // },

      handleCurrentChange(val) {
        this.currentPage = val
        this.getList()
      },
      getList() {
        ScriptWritingList({ page: this.currentPage, ...this.formInline }).then(
          (res) => {
            this.tableData = res.data.list
            console.log('表格数据wei', this.tableData)
            this.total = res.data.total
          }
        )
      }
    }
  }
</script>
<style lang="scss" scoped>
  .scriptWriting {
    ::v-deep {
      .el-image {
        width: 50px !important;
        height: 50px !important;

        .el-image__error {
          font-size: 12px;
        }
      }
    }
  }
</style>
